﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using spk_eAuction.Classes;
namespace spk_eAuction
{
    public partial class Bids : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(Request.QueryString["view"] != null && Request.QueryString["view"].ToString().Equals("pay_failed"))
                if (HttpContext.Current.Session["shoppingcart"] != null && HttpContext.Current.Session["payment_type"] != null &&
                    HttpContext.Current.Session["payment_type"].ToString().Equals("coins"))
                        GridView1 = HttpContext.Current.Session[""] as GridView;
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Label LabelNo = e.Row.FindControl("LabelNo") as Label;
            if (LabelNo != null)
                LabelNo.Text = ( 1 + e.Row.RowIndex).ToString();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            float total = 0f;
            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox CheckBox1 = row.FindControl("CheckBox1") as CheckBox;
                Label Label6 = row.FindControl("Label6") as Label;
                if (Label6 == null || CheckBox1 == null || CheckBox1.Checked == false)
                    continue;
                total += float.Parse(Label6.Text.Split(' ')[0].Replace(",","").Replace(".", ""));
            }
            if (total == 0f)
            {
                Response.Write("<script> alert('"+ Resources.Bids.aspx.Error_Empty_Item +"'); </script>");
                return;
            }
            total /= Config.SPaypal.Rates.USD;
            HttpContext.Current.Session["payment_amt"] = (int)total;
            HttpContext.Current.Session["payment_type"] = "coins";
            HttpContext.Current.Session["shoppingcart"] = GridView1;
            
            Response.Redirect("~/Paypal/expresscheckout.aspx");
        }
    }
}